<script setup>
  import { ref } from 'vue'
  import { listEnterprise, getEnterprise } from '@/api/dashboard'
  const popup = ref(null)
  function open() {
    popup.value.open()
    listEnterprise({
      pageNum: 1,
      pageSize: 1000
    }).then(res => {
      enterprise.value = res.rows
      if (enterprise.value.length > 0) {
        getEnterprise(enterprise.value[0].id).then(res => {
          activeEnterprise.value = res.data
          activeEnterprise.value.imgArray = activeEnterprise.value.imgArray.split(',')
        })
      }
    })
  }
  defineExpose({ open })
  const enterprise = ref([])
  const activeIndex = ref(0)
  const activeEnterprise = ref({})
  function handleCover(imgArray) {
    imgArray = imgArray.split(',')
    if (imgArray) {
      return imgArray[0]
    }
    return '/profile/upload/assets/black.png'
  }
  function handleClick(index) {
    activeIndex.value = index
    getEnterprise(enterprise.value[index].id).then(res => {
      activeEnterprise.value = res.data
      activeEnterprise.value.imgArray = activeEnterprise.value.imgArray.split(',')
    })
  }
</script>

<template>
  <Popup width="1180.72" height="901.46" ref="popup" title="天台黄茶茶加工">
    <div class="flex-center">
      <ul>
        <li
          v-for="(item, index) in enterprise"
          class="enterprise"
          @click="handleClick(index)"
        >
          <img v-cover="handleCover(item.imgArray)" />
          <p class="name" v-if="activeIndex == index">{{ item.name }}</p>
          <div class="mask" v-else>{{ item.name }}</div>
        </li>
      </ul>
      <div class="profile">
        <div class="brief">企业简介</div>
        <div class="img">
          <el-carousel height="340px" arrow="never">
            <el-carousel-item v-for="item in activeEnterprise.imgArray" :key="item">
              <img v-cover="item" />
            </el-carousel-item>
          </el-carousel>
          <!-- <img src="/src/assets/img/enterprise/1.png" /> -->
        </div>
        <p class="introduce" v-html="enterprise[activeIndex].brief"></p>
        <div class="brief">产品</div>
        <div class="root">
          <div class="swiper">
            <div
              class="swiper-item"
              v-for="item in activeEnterprise.teaProductList"
            >
              <img v-cover="item.cover" />
              <p class="name">{{ item.price }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </Popup>
</template>

<style lang="scss" scoped>
  ul {
    overflow-y: scroll;
    height: 740px;
    .enterprise {
      cursor: pointer;
      width: 220px;
      height: 108px;
      border: 2px solid #20caff;
      position: relative;
      margin-bottom: 20px;
      .mask {
        width: 220px;
        height: 108px;
        background: rgba(0, 0, 0, 0.6);
        border-radius: 0px 0px 0px 0px;
        position: absolute;
        top: 0;
        z-index: 1;
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 14px;
        color: rgba(255, 255, 255, 0.7);
        line-height: 108px;
        text-align: center;
      }
    }
  }
  .profile {
    margin-left: 46px;
    width: 820px;
    height: 740px;
    background: #092435;
    box-shadow: inset 0px 0px 16px 0px rgba(45, 230, 255, 0.56);
    border-radius: 0px 0px 0px 0px;
    border: 2px solid rgba(6, 165, 255, 0.5);
    padding: 20px;
    .brief {
      background: url('/src/assets/img/enterprise/brief.png') no-repeat;
      background-position: center;
      width: 360px;
      height: 36px;
      line-height: 32px;
      font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
      font-weight: bolder;
      font-size: 20px;
      color: #fcfbff;
      padding-left: 12px;
      text-shadow: 0px 2px 6px #00a3ff;
    }
    .img {
      margin-top: 12px;
      width: 780px;
      height: 344px;
      border-radius: 0px 0px 0px 0px;
      border: 2px solid #20caff;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .introduce {
      height: 66px;
      width: 780px;
      margin: 14px 0 32px 0;
      font-family: PingFang SC, PingFang SC;
      font-weight: 400;
      font-size: 16px;
      color: #ffffff;
      overflow: scroll;
    }
  }
  .enterprise,
  .swiper-item {
    width: 247px;
    height: 142px;
    border-radius: 0px 0px 0px 0px;
    border: 2px solid #20afff;
    position: relative;
    img {
      width: 100%;
      height: 100%;
    }
    .name {
      text-align: center;
      line-height: 32px;
      width: 100%;
      height: 32px;
      background: rgba(0, 0, 0, 0.52);
      border-radius: 0px 0px 0px 0px;
      color: #ffffff;
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      font-size: 16px;
      position: absolute;
      bottom: 0;
    }
  }
  .root {
    height: 780px;
    width: 200px;
    transform: rotateZ(-90deg) rotateY(180deg);
    transform-origin: left top;
    overflow: scroll;
    margin-top: -40px;
  }
  .swiper {
    width: 100%;
    height: 100%;
    display: flex;
    transform-origin: left bottom;
    flex-wrap: nowrap;
    flex-direction: column;
    .swiper-item {
      transform: rotateZ(-90deg) rotateY(180deg);
      margin-bottom: 70px;
      margin-top: 52px;
    }
  }
</style>
